/*
Eteria IRC Client, an RFC 1459 compliant client program written in Java.
Copyright (C) 2001  Christian Buck <cbuck at lantis.de>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.util.StringTokenizer;

import ar.com.jkohen.awt.ImageButton;
import ar.com.jkohen.util.Resources;
import com.splendid.awtchat.*;

public class HelpBox extends Dialog implements ActionListener
{
	private EIRC eirc;
	private Frame frame;
    private HelpWindow help;

	private Resources res;

    public HelpBox(EIRC eirc, Frame frame)
	{
    	super(frame);
		this.eirc = eirc;
		this.frame = frame;

		setFont(eirc.getFont());

        GridBagLayout gb = new GridBagLayout();
    	GridBagConstraints gbc = new GridBagConstraints();
        setLayout(gb);

        gbc.insets = new Insets(2, 2, 2, 2);

        help = new HelpWindow(eirc, "help");

        gbc.fill = GridBagConstraints.BOTH;
    	gbc.weighty = 1.0;
      	gbc.weightx = 1.0;
    	gb.setConstraints(help, gbc);
    	add(help);
      	gbc.weightx = 0.0;
    	gbc.weighty = 0.0;
        gbc.fill = GridBagConstraints.NONE;

    	gbc.gridy = 1;

    	Panel bottom_panel = new Panel();
    	GridBagLayout gb2 = new GridBagLayout();
    	GridBagConstraints gbc2 = new GridBagConstraints();
    	bottom_panel.setLayout(gb2);

    	gbc2.weightx = 1.0;
        gbc2.insets = new Insets(0, 2, 0, 2);

        ImageButton b = new ImageButton(res.getString("close"));
    	b.setActionCommand("ok");
        gb2.setConstraints(b, gbc2);
    	bottom_panel.add(b);
        b.addActionListener(this);
        b.setEnabled(true);

        gb.setConstraints(bottom_panel, gbc);
    	add(bottom_panel);

		setText();
		setResizable(true);
		setTitle(res.getString("help"));
		
		show();
    }
	
	public void setText()
	{
		help.clear();
		String txt = res.getHelp();
		
		if (txt == null || txt.equals(""))
			return;
		
		StringTokenizer stk = new StringTokenizer(txt, "\n");
		while (stk.hasMoreTokens())
		{
			String s = stk.nextToken();
			help.append(s);
		}

		help.home();
	}

	public void setBackground(Color c)
    {
		super.setBackground(c);
    }

	public void setForeground(Color c)
    {
		super.setForeground(c);
    }

    public void setTextBackground(Color c)
    {
		help.setBackground(c);
    }

    public void setTextForeground(Color c)
    {
		help.setForeground(c);
    }

    public void actionPerformed(ActionEvent ev)
    {
		String ac = ev.getActionCommand();

		if (ac.equals("ok"))
			processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    }

	public void show()
	{
		setSize(350, 350);
       	setLocation((frame.getSize().width - getSize().width) / 2 + frame.getLocation().x, (frame.getSize().height - getSize().height) / 2 + frame.getLocation().y);

		setBackground(eirc.getBackground());
		setForeground(eirc.getForeground());
		super.show();
	}
}
